package com.tcenter.dao.entities;


import java.util.Date;
import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 *
 */
@Entity
@Table(name = "user_role", catalog = "tcenterdb")
public class UserRole implements java.io.Serializable {

    private UserRoleId id;
    private User userByGrantedBy;
    private User userByUserId;
    private Role role;
    private Date grantedOn;


    public UserRole() {
    }

    public UserRole(UserRoleId id, User userByUserId, Role role) {
        this.id = id;
        this.userByUserId = userByUserId;
        this.role = role;
    }

    public UserRole(UserRoleId id, User userByGrantedBy, User userByUserId,
                    Role role, Date grantedOn) {
        this.id = id;
        this.userByGrantedBy = userByGrantedBy;
        this.userByUserId = userByUserId;
        this.role = role;
        this.grantedOn = grantedOn;
    }


    @EmbeddedId
    @AttributeOverrides({
            @AttributeOverride(name = "userId", column = @Column(name = "user_id", nullable = false)),
            @AttributeOverride(name = "roleId", column = @Column(name = "role_id", nullable = false))})
    public UserRoleId getId() {
        return this.id;
    }

    public void setId(UserRoleId id) {
        this.id = id;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "granted_by")
    public User getUserByGrantedBy() {
        return this.userByGrantedBy;
    }

    public void setUserByGrantedBy(User userByGrantedBy) {
        this.userByGrantedBy = userByGrantedBy;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "user_id", nullable = false, insertable = false, updatable = false)
    public User getUserByUserId() {
        return this.userByUserId;
    }

    public void setUserByUserId(User userByUserId) {
        this.userByUserId = userByUserId;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "role_id", nullable = false, insertable = false, updatable = false)
    public Role getRole() {
        return this.role;
    }

    public void setRole(Role role) {
        this.role = role;
    }

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "granted_on", length = 19)
    public Date getGrantedOn() {
        return this.grantedOn;
    }

    public void setGrantedOn(Date grantedOn) {
        this.grantedOn = grantedOn;
    }

}
